package com.dome.backtemplate.config.filter;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.dfa.SensitiveUtil;
import com.dome.backtemplate.config.file.WebAppDataProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.io.File;

/**
 * @Description 敏感词初始化加载
 * @Author 小乌龟
 * @Date 2023/3/7 18:51
 */
@Configuration
@Slf4j
public class SensitiveWordConfig implements InitializingBean {
    @Autowired
    private WebAppDataProperties webAppDataProperties;

    @Override
    public void afterPropertiesSet(){
        //自己对应的文件路径 存放地址
        File file = FileUtil.file(webAppDataProperties.getMappingLocation()+"sensitiveWord.txt");
        FileReader reader = new FileReader(file);
        SensitiveUtil.init(reader.readLines());
        log.info("initialize bean:{}", SensitiveWordConfig.class.getName());
    }
}
